﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
public partial class ttdoanhnghiep : System.Web.UI.Page
{

    public static string check = "";

    public void fillData()
    {
      
        MySqlConnection con = new MySqlConnection(DatabaseHandler.strConnect);
        con.Open();


        MySqlDataAdapter ad = new MySqlDataAdapter("select * from tbl_doanhnghiep", con);
        DataSet ds = new DataSet();
        ad.Fill(ds, "tbl");



        for (int i = 0; i < ds.Tables["tbl"].Rows.Count; i++)
        {
            DataRow dr;
            dr = ds.Tables["tbl"].Rows[i];
            if (dr["IDDN"].ToString() == Variables.IDDN.ToString())
            {

                txtngphongvan.Text = dr["NGUOIPV"].ToString();
                txtngayphongvan.Text = dr["NGAYPV"].ToString();
                txtmasodn.Text = dr["IDDN"].ToString();
                txttendn.Text = dr["TENDN"].ToString();
                txttenta.Text = dr["TENTA"].ToString();
                txttenvt.Text = dr["TENVT"].ToString();
               
                cbnhomnganh.Text = dr["NHOMNGANH"].ToString();

                addCombobox.addcb(cbnghanhcon, "select * from tbl_ncon where NHOMNGANH='" + dr["NHOMNGANH"] + "'", "Ten");
                cbnghanhcon.Text = dr["NGANHCON"].ToString();
                cbloaidn.Text = dr["LOAIHINHDN"].ToString();
                cbkhucn.Text = dr["KHUCN"].ToString();
                cbhuyen.Text = dr["QUANHUYEN"].ToString();
                txtdiachi.Text = dr["DIACHI"].ToString();
                txtdt.Text = dr["DIENTHOAI"].ToString();
                txtfax.Text = dr["FAX"].ToString();
                txtwebsite.Text = dr["WEBSITE"].ToString();
                txtemail.Text = dr["EMAIL"].ToString();

            }

        }

       

    }
    protected void Page_Load(object sender, EventArgs e)
    {
       addCombobox.addcb(cbhuyen, "select * from tbl_huyen", "Huyen");
       addCombobox.addcb(cbkhucn, "select * from tbl_khucn", "KHUCN");
       addCombobox.addcb(cbnhomnganh, "select * from tbl_nganh", "TenNganh");
       check = cbnhomnganh.Text;
       fillData();
      
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        DatabaseHandler db = new DatabaseHandler();
        db.connect();
        string sql = "update tbl_doanhnghiep set NGUOIPV='" + txtngphongvan.Text + "'"+
                                                 "NGAYPV='" + txtngayphongvan.Text + "'"+
                                                 "TENDN='" + txttendn.Text + "'" +
                                                 "TENTA='"+txttenta.Text + "'"+
                                                 "TENVT='" + txttenvt.Text+"'"+
                                                 "NHOMNGANH='" + cbnhomnganh.Text + "'" +
                                                 "NGANHCON='"+cbnghanhcon.Text + "'" +
                                                 "LOAIHINHDN='"+cbloaidn.Text + "'" +
                                                 "KHUCN='"+cbkhucn.Text + "'" + 
                                                 "QUANHUYEN='"+cbhuyen.Text + "'"+
                                                 "DIACHI='" + txtdiachi.Text + "'"+ 
                                                 "DIENTHOAI='"+ txtdt.Text + "'" +
                                                 "FAX='"+txtfax.Text + "'" +
                                                 "WEBSITE='"+txtwebsite.Text + "'" +
                                                 "EMAIL='" + txtemail.Text + "' WHERE IDDN='"+txtmasodn.TemplateControl+"'";

        db.ThemDuLieu(sql);
        
    
        db.close();
        lbShow.Text = "Lưu thông tin doanh nghiệp thành công!";

        btn_NhapChiSo.Enabled = true;
        

    }


    protected void btn_NhapChiSo_Click(object sender, EventArgs e)
    {
        Response.Redirect("GiatriOrganization.aspx");
    }
    protected void cbnhomnganh_SelectedIndexChanged(object sender, EventArgs e)
    {

      
        cbnhomnganh.Items.Clear();
        addCombobox.addcb(cbnhomnganh, "select * from tbl_nganh", "TenNganh");
        cbnhomnganh.Text = check;
        cbnghanhcon.Items.Clear();
        addCombobox.addcb(cbnghanhcon, "select * from tbl_ncon where NHOMNGANH='" + check + "'", "ten");
        //
        //cbnghanhcon.Items.Clear();
        //string chose = "";
        //chose = cbnhomnganh.SelectedItem.ToString();
        //cbnghanhcon.Text = chose;
        //cbnhomnganh.Items.Clear();
        //addCombobox.addcb(cbnhomnganh, "select * from tbl_nganh", "TenNganh");
        //cbnhomnganh.Text = chose;
    }
    
   
    
    protected void LinkButton17_Click1(object sender, EventArgs e)
    {
        Response.Redirect("HienThi_TTDoanhNghiep.aspx");
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");
    }
    protected void LinkButton16_Click(object sender, EventArgs e)
    {
        Response.Redirect("Nhap_TTDoanhNghiep.aspx");
    }
    protected void LinkButton24_Click1(object sender, EventArgs e)
    {
        Response.Redirect("Xuatdulieu.aspx");
    }
    protected void cbnghanhcon_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}